package sticker.decompress.name;

import android.net.Uri;
import sticker.decompress.IIdGenerator;

import java.io.File;

public class DefaultNameGenerator implements INameGenerator {

    String defaultNamePrefix = "表情";

    IIdGenerator idGenerator;

    public DefaultNameGenerator() {
        idGenerator = SharePrefIdGenerator.getInstance();
    }

    @Override
    public String generateName(Uri uri) {

        String path = uri.getPath();
        if (path == null)
            return defaultNamePrefix + getId();
        int pathEnd = path.lastIndexOf('/');
        if (pathEnd != -1)
            return path.substring(pathEnd);
        return path;
    }

    @Override
    public String generateName(File file) {

        String path = file.getPath();
        int pathEnd = path.lastIndexOf('/');
        if (pathEnd != -1)
            return path.substring(pathEnd);
        return path;
    }

    /**
     * 生成递增的id
     *
     * @return
     */
    private int getId() {
        return idGenerator.getId();
    }


}
